package com.dlc.felear.xiaoensale.activity;

import android.content.Intent;
import android.graphics.Paint;
import android.text.InputType;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import com.dlc.felear.xiaoensale.R;
import com.dlc.felear.xiaoensale.adapter.OperatorItemAdapter;
import com.dlc.felear.xiaoensale.constant.Constant;
import com.dlc.felear.xiaoensale.constant.TempData;
import com.dlc.felear.xiaoensale.customView.ConfirmDialog;
import com.dlc.felear.xiaoensale.customView.DoubleSelectDialog;
import com.dlc.felear.xiaoensale.customView.SelectCatgerDialog;
import com.dlc.felear.xiaoensale.customView.SingleInputDialog;
import com.dlc.felear.xiaoensale.customView.TextInputDialog;
import com.dlc.felear.xiaoensale.dao.CookingMenuDao;
import com.dlc.felear.xiaoensale.dao.FlavourSpeedDao;
import com.dlc.felear.xiaoensale.dao.LocalUserDao;
import com.dlc.felear.xiaoensale.dao.MenuFoodMaterialDao;
import com.dlc.felear.xiaoensale.dao.OperatorDao;
import com.dlc.felear.xiaoensale.deviceControlSf.OperatorAutoHandle;
import com.dlc.felear.xiaoensale.deviceUtil.TopbarHelper;
import com.dlc.felear.xiaoensale.entity.CookingMenu;
import com.dlc.felear.xiaoensale.entity.LocalUser;
import com.dlc.felear.xiaoensale.entity.MenuFoodMaterial;
import com.dlc.felear.xiaoensale.entity.Operator;
import com.dlc.felear.xiaoensale.helper.CookingMenuMangerHelper;
import com.dlc.felear.xiaoensale.helper.JsonHelper;
import com.dlc.felear.xiaoensale.helper.Session;
import com.dlc.felear.xiaoensale.utils.DateTimeUtil;
import com.dlc.felear.xiaoensale.utils.NumToStringUtil;
import com.dlc.felear.xiaoensale.utils.UuidUtil;
import com.itdlc.android.library.base.BaseActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 菜谱编制页面
 */
public class EditMenuActivity extends BaseActivity implements ConfirmDialog.ConfirmDialogCallback,
        DoubleSelectDialog.DoubleSelectCallback, TextInputDialog.TextInputDialogCallback,
        SingleInputDialog.SingleDialogCallback, SelectCatgerDialog.SelectCatgerDialogCallback {
    private static final String TAG = "EditMenuActivity";
    private static final int GZ_1 = 1;
    private static final int GZ_2 = 2;
    private static final int GZ_3 = 3;
    private static final int GZ_4 = 4;
    private static final int GZ_5 = 5;
    @BindView(R.id.et_name_1)
    EditText etName1;
    @BindView(R.id.et_name_2)
    EditText etName2;
    @BindView(R.id.et_name_3)
    EditText etName3;
    @BindView(R.id.et_name_4)
    EditText etName4;
    @BindView(R.id.et_name_5)
    EditText etName5;
    @BindView(R.id.et_weight_1)
    EditText etWeight1;
    @BindView(R.id.et_weight_2)
    EditText etWeight2;
    @BindView(R.id.et_weight_3)
    EditText etWeight3;
    @BindView(R.id.et_weight_4)
    EditText etWeight4;
    @BindView(R.id.et_weight_5)
    EditText etWeight5;
    @BindView(R.id.et_emnu_name)
    EditText etEmnuName;
    @BindView(R.id.et_emnu_total_weight)
    EditText etEmnuWeight;
    @BindView(R.id.lv_action)
    ListView listView;
    @BindView(R.id.tv_tips)
    TextView tvTips;
    private Map<Integer, MenuFoodMaterial> foodMaterials = new HashMap<>();
    private TopbarHelper topbarHelper;
    private OperatorItemAdapter operatorItemAdapter;
    private CookingMenu cookingMenu;
    private CookingMenuDao cookingMenuDao;
    private OperatorDao operatorDao;
    private ConfirmDialog confirmDialog;
    private int foodNameIndex = 0;
    private MenuFoodMaterialDao menuFoodMaterialDao;
    private String menuTips = "";
    private TextInputDialog textInputDialog;
    private SingleInputDialog singleInputDialog;
    private List<Operator> srcOperators;
    private DoubleSelectDialog doubleSelectDialog;
    private String paramer1, paramer2, paramer3, paramer4;
    private int cookingType = 1;
    private FlavourSpeedDao flavourSpeedDao;
    private SelectCatgerDialog selectCatgerDialog;
    private CookingMenuMangerHelper cookingMenuMangerHelper;
    private String deviceType = "M400";

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_edit_menu;
    }

    @Override
    protected void initialView() {
        singleInputDialog = new SingleInputDialog(this, this);
        singleInputDialog.setEtInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
        singleInputDialog.setMiWen();
        cookingMenu=new CookingMenu();
        singleInputDialog.setTips("密码");
        singleInputDialog.setHintMsg("请输入管理密码");
        topbarHelper = new TopbarHelper(this);
        topbarHelper.setNavActivity(CcLauncherActivity.class);
        topbarHelper.setTitle("编写菜谱");
        textInputDialog = new TextInputDialog(this, this);
        cookingMenuDao = new CookingMenuDao(this);
        cookingMenuMangerHelper = CookingMenuMangerHelper.getInstance(this, cookingMenuDao);
        menuFoodMaterialDao = new MenuFoodMaterialDao(this);
        operatorDao = new OperatorDao(this);
        flavourSpeedDao = new FlavourSpeedDao(this);
        confirmDialog = new ConfirmDialog(this, this);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                operatorItemAdapter.setIndex(position);
            }
        });
        tvTips.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
        operatorItemAdapter = new OperatorItemAdapter(this, "src1");
        operatorItemAdapter.setEnableDelete(false);
        listView.setAdapter(operatorItemAdapter);
        etEmnuWeight.setText(Integer.toString(1));
        operatorItemAdapter.initFirstOperator();
        deviceType = Session.getSession().getString(Constant.D_GT_TYPE, "M260");
        doubleSelectDialog = new DoubleSelectDialog(this, this);
        selectCatgerDialog = new SelectCatgerDialog(this, this);
    }


    @Override
    protected void initData() {
        try {
            operatorItemAdapter.setCcCookingTimeParamer(paramer1);
            operatorItemAdapter.setCookingType(cookingType);
            operatorItemAdapter.setItems(TempData.getDefaultOperater(flavourSpeedDao));
        } catch (Exception e) {
            showShortToast("数据异常:" + e.getMessage());
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        try {
            Log.e(TAG, "data=" + JsonHelper.toJson(data));
            if (requestCode == 1024) {
                String name = data.getExtras().getString(Constant.OPERATOR_NAME);
                int value = data.getExtras().getInt(Constant.OPERATOR_VALUE_1, 0);
                int value1 = data.getExtras().getInt(Constant.OPERATOR_VALUE_2, 0);
                Log.e(TAG, "name=" + name + " value1=" + value + " value2=" + value1);
                operatorItemAdapter.updateData(name, value, value1,getEtValue(etEmnuWeight));
            } else if (requestCode == 1025) {
                String foodName = data.getExtras().getString(Constant.FOOD_NAME);
                int id = data.getExtras().getInt(Constant.FOOD_ID);
                if (TextUtils.equals(foodName, Constant.FOOD_NAME_DELETE) && id == 0) {
                    deleteFoods();
                    initEtName("");
                    return;
                }
                Log.e(TAG, "foodName:" + foodName + " foodId:" + id);
                foodMaterials.put(foodNameIndex, menuFoodMaterialDao.queryForFoodId(id));
                initEtName(foodName);
            } else if (requestCode == 1027) {
                String paramer1 = data.getStringExtra("paramer1");
                Log.e(TAG, "paramer1:" + paramer1);
                if (paramer1 != null) {
                    this.paramer1 = paramer1;
                    operatorItemAdapter.setCcCookingTimeParamer(paramer1);
                }
            }
        } catch (Exception e) {
            showShortToast("数据异常");
        }
    }


    /**
     * 删除食材
     */
    private void deleteFoods() {
        try {
            MenuFoodMaterial menuFoodMaterial = foodMaterials.get(foodNameIndex);
            if (menuFoodMaterial != null) {
                menuFoodMaterialDao.delete(menuFoodMaterial);
            }
            foodMaterials.put(foodNameIndex, null);
        } catch (Exception e) {
            showShortToast("数据异常:" + e.getMessage());
        }
    }

    private void initEtName(String name) {
        try {
            switch (foodNameIndex) {
                case 1:
                    etName1.setText(name);
                    break;
                case 2:
                    etName2.setText(name);
                    break;
                case 3:
                    etName3.setText(name);
                    break;
                case 4:
                    etName4.setText(name);
                    break;
                case 5:
                    etName5.setText(name);
                    break;
            }
        } catch (Exception e) {
            showShortToast("数据异常:" + e.getMessage());
        }
    }


    @OnClick({R.id.tv_save, R.id.et_name_1, R.id.et_name_2, R.id.et_name_3, R.id.et_name_4,
            R.id.et_name_5, R.id.tv_tips, R.id.tv_xiugai, R.id.tv_s_cat})
    public void onClick(View view) {
        try {
            switch (view.getId()) {
                case R.id.tv_save:
                    saveEmnu(231);
                    break;
                case R.id.et_name_1:
                    selectFoodMaterial(GZ_1);
                    break;
                case R.id.et_name_2:
                    selectFoodMaterial(GZ_2);
                    break;
                case R.id.et_name_3:
                    selectFoodMaterial(GZ_3);
                    break;
                case R.id.et_name_4:
                    selectFoodMaterial(GZ_4);
                    break;
                case R.id.et_name_5:
                    selectFoodMaterial(GZ_5);
                    break;
                case R.id.tv_tips:
                    showTextInputDialog();
                    break;
                case R.id.tv_xiugai:
                    change();
                    break;
                case R.id.tv_s_cat:
                    doubleSelectDialog.showDialog(R.id.tv_s_cat);
                    break;
            }
        } catch (Exception e) {
            showShortToast("数据异常:" + e.getMessage());
        }
    }

    private void change() {
        try {
            String s = etEmnuWeight.getText().toString().trim();
            if (TextUtils.isEmpty(s)) {
                showShortToast("输入框不能为空");
                return;
            }
            if (TextUtils.isEmpty(paramer1)) {
                showShortToast("请先设置参数再使用");
                return;
            }
            if (s.contains(".")) {
                int d1 = s.indexOf(".");
                Log.e(TAG, "length=" + s.length() + " d1=" + d1);
                if (s.length() - d1 > 2 && d1 > 0) {
                    showShortToast("只支持一位小数");
                    etEmnuWeight.setText(s.substring(0, d1 + 2));
                    return;
                }
            }
            if(getStringFloatValue(cookingMenu.getSpecification())<=0){
                cookingMenu.setSpecification(s);
                operatorItemAdapter.resetAllParamer(getStringFloatValue(s));
                return;
            }
            float tempSize=getStringFloatValue(s)/getStringFloatValue(cookingMenu.getSpecification());
            cookingMenu.setSpecification(s);
            operatorItemAdapter.resetAllParamer(tempSize);
        } catch (Exception e) {
            showShortToast("请输入有效数字");
        }
    }

    private float getStringFloatValue(String value){
        if(TextUtils.isEmpty(value)){
          return 0f;
        }
        try {
          return Float.parseFloat(value);
        }catch (Exception e){

        }
        return 0f;
    }

    /**
     * 保存菜谱
     */
    private void saveEmnu(int id) {
        try {
            if(!NumToStringUtil.isInteger(getEtString(etEmnuWeight))){
                showLongToast("重量请输入正整数");
               return;
            }
            etEmnuName.setText(getEtString(etEmnuName).toUpperCase());
            if (TextUtils.isEmpty(getEtString(etEmnuName))) {
                showLongToast("请输入菜品名称");
                return;
            }
            if (!cookingMenuMangerHelper.isHasCat(getEtString(etEmnuName))) {
                showLongToast("菜谱名称要包含分类组合字母");
                selectCatgerDialog.showDialog(cookingMenuMangerHelper.getCatLists());
                return;
            }
            if (TextUtils.isEmpty(getEtString(etEmnuWeight))) {
                showLongToast("菜品总重量不能为0");
                return;
            }

            if (getEtValue(etEmnuWeight) < 1) {
                showLongToast("菜品总重量不能为小于1斤");
                return;
            }
            if (TextUtils.isEmpty(paramer1) && TextUtils.isEmpty(paramer3) & TextUtils.isEmpty(paramer4)) {
                showLongToast("餐谱公式不能为空");
                return;
            }

            if (checkEt()) {
                return;
            }
            if (checkOperator()) {
                return;
            }
            singleInputDialog.showDialog(id);
        } catch (Exception e) {
            showShortToast("数据异常:" + e.getMessage());
        }
    }

    /**
     * 设置菜谱的值
     *
     * @param date
     * @param msg
     */
    private void saveInfo(String date, String msg) {
        try {
            cookingMenu.setCreateTime(date);
            cookingMenu.setUpdateTime(DateTimeUtil.getCurrentTImeYMD());
            cookingMenu.setName(getEtString(etEmnuName));
            cookingMenu.setSpecification(Integer.toString(1));
            cookingMenu.setFoodMaterials(getFoodMaterial(cookingMenu.getId()));
            cookingMenu.setOperators(setMId(cookingMenu.getId()));
            cookingMenu.setDuration(getTotalCostTime(cookingMenu.getOperators()));
            Log.e(TAG, "保存信息:" + JsonHelper.toJson(cookingMenu));
            cookingMenuDao.createOrUpdateAll(cookingMenu);
            Log.e(TAG, "菜谱保存成功");
            showLongToast(msg);
            cookingMenuMangerHelper.updateCookingMenu(cookingMenu);
        } catch (Exception e) {
            Log.e(TAG, e.getMessage());
        }
    }



    private int getFoodNameId(int index) {
        if (!foodMaterials.containsKey(index)) {
            return -1;
        }
        return foodMaterials.get(index).getFoodid();
    }


    /**
     * 获取菜谱食材
     *
     * @param id
     * @return
     */
    private List<MenuFoodMaterial> getFoodMaterial(String id) {
        List<MenuFoodMaterial> list = new ArrayList<>();
        try {
            if (!TextUtils.isEmpty(getEtString(etName1)) && !TextUtils.isEmpty(getEtString(etWeight1))) {
                MenuFoodMaterial temp1 = getFoodMaterial(id, etName1, etWeight1, GZ_1);
                if (temp1.getWeight() > 0) {
                    list.add(temp1);
                } else {
                    menuFoodMaterialDao.delete(temp1);
                }
            }
            if (!TextUtils.isEmpty(getEtString(etName2)) && !TextUtils.isEmpty(getEtString(etWeight2))) {
                MenuFoodMaterial temp2 = getFoodMaterial(id, etName2, etWeight2, GZ_2);
                if (temp2.getWeight() > 0) {
                    list.add(temp2);
                } else {
                    menuFoodMaterialDao.delete(temp2);
                }
            }
            if (!TextUtils.isEmpty(getEtString(etName3)) && !TextUtils.isEmpty(getEtString(etWeight3))) {
                MenuFoodMaterial temp3 = getFoodMaterial(id, etName3, etWeight3, GZ_3);
                if (temp3.getWeight() > 0) {
                    list.add(temp3);
                } else {
                    menuFoodMaterialDao.delete(temp3);
                }
            }
            if (!TextUtils.isEmpty(getEtString(etName4)) && !TextUtils.isEmpty(getEtString(etWeight4))) {
                MenuFoodMaterial temp4 = getFoodMaterial(id, etName4, etWeight4, GZ_4);
                if (temp4.getWeight() > 0) {
                    list.add(temp4);
                } else {
                    menuFoodMaterialDao.delete(temp4);
                }
            }
            if (!TextUtils.isEmpty(getEtString(etName5)) && !TextUtils.isEmpty(getEtString(etWeight5))) {
                MenuFoodMaterial temp5 = getFoodMaterial(id, etName5, etWeight5, GZ_5);
                if (temp5.getWeight() > 0) {
                    list.add(temp5);
                } else {
                    menuFoodMaterialDao.delete(temp5);
                }
            }
            for (int i = 0; i < list.size(); i++) {
                MenuFoodMaterial menuFoodMaterial = list.get(i);
                float weight = Float.parseFloat(getEtString(etEmnuWeight));
                float stdW = menuFoodMaterial.getWeight() / weight;
                menuFoodMaterial.setWeight((int) stdW);
            }
        } catch (Exception e) {
            showShortToast("数据异常:" + e.getMessage());
        }
        return list;
    }

    /**
     * 获取食材
     *
     * @param id
     * @param name
     * @param weight
     * @param num
     * @return
     */
    private MenuFoodMaterial getFoodMaterial(String id, EditText name, EditText weight, int num) {
        MenuFoodMaterial foodMaterial = null;
        try {
            String ttt1 = name.getText().toString();
            String ttt2 = weight.getText().toString();
            if (!TextUtils.isEmpty(ttt1) && !TextUtils.isEmpty(ttt2)) {
                foodMaterial = new MenuFoodMaterial();
                foodMaterial.setCid(id);
                foodMaterial.setNumber(num);
                foodMaterial.setFoodid(getFoodNameId(num));
                foodMaterial.setFoodName(getEtString(name));
                foodMaterial.setId(getFoodsId(id, num));
                foodMaterial.setWeight((int) getEtValue(weight));
                foodMaterial.setSid(Integer.toString(getFoodNameId(num)));
                foodMaterial.setType(Constant.FOODS_TYPE_2);
            }
        } catch (Exception e) {
            showShortToast("数据异常:" + e.getMessage());
        }
        return foodMaterial;
    }

    /**
     * 获取食材id
     *
     * @param cid
     * @param id
     * @return
     */
    private String getFoodsId(String cid, int id) {
        return cid.substring(0, cid.length() - 1) + id;
    }

    /**
     * 操作列表
     *
     * @param id
     * @return
     */
    private List<Operator> setMId(String id) {
        int duration = 0;
        List<Operator> data = new ArrayList<>();
        try {
            float weight = getEtValue(etEmnuWeight);
            List<Operator> list = OperatorAutoHandle.getInstance(null, null, TAG)
                    .changgeOperator(operatorItemAdapter.getData(), 1 / weight, paramer1, cookingType);
            for (Operator operator : list) {
                if (TextUtils.equals(operator.getName(), Constant.ACTION_NAME_SHUI)
                        || TextUtils.equals(operator.getName(), Constant.ACTION_NAME_CCSC)) {
                    operator = operatorItemAdapter.getStdOperator(operator, 1);
                }
                operator.setmId(id);
                data.add(operator);
                duration += operator.getDelayTime();
            }
            cookingMenu.setDuration(duration);
        } catch (Exception e) {
            showShortToast("数据异常:" + e.getMessage());
        }
        return data;
    }

    /**
     * 检查操作步骤有效性
     *
     * @return
     */
    private boolean checkOperator() {
        try {
            boolean temp = false;
            for (Operator operator : operatorItemAdapter.getData()) {
                if (!TextUtils.isEmpty(operator.getName()) &&
                        TextUtils.equals(operator.getName(), "请选择")) {
                    showLongToast("请填入有效操作");
                    return true;
                }
                if (operator.getDelayTime() <= 0) {
                    showLongToast("时间不能为0");
                    return true;
                }
                if (TextUtils.equals(operator.getName(), Constant.ACTION_NAME_CCSC)) {
                    temp = true;
                }
            }
            if (!temp) {
                showLongToast("请添加炒菜时长指令，炒菜步骤中必须含有炒菜时长该指令");
                return true;
            }
        } catch (Exception e) {
            showShortToast("数据异常:" + e.getMessage());
        }
        return false;
    }

    /**
     * 统计菜谱时长
     *
     * @param list
     * @return
     */
    private int getTotalCostTime(List<Operator> list) {
        int temp = 0;
        if (list != null || !list.isEmpty()) {
            for (Operator operator : list) {
                temp += operator.getDelayTime();
            }
        }
        return temp;
    }

    /**
     * 检查输入框内容的有效性
     *
     * @return
     */
    private boolean checkEt() {
        try {
            String names = getEtString(etName1) + getEtString(etName2) +
                    getEtString(etName3) + getEtString(etName4) + getEtString(etName5);
            if (TextUtils.isEmpty(names)) {
                showLongToast("食材名字不能全部为空");
                return true;
            }
            float weights = getEtValue(etWeight1) + getEtValue(etWeight2) +
                    getEtValue(etWeight3) + getEtValue(etWeight4) + getEtValue(etWeight5);
            if (weights <= 0) {
                showLongToast("素材重量不能全部为0");
                return true;
            }
        } catch (Exception e) {
            showShortToast("数据异常:" + e.getMessage());
        }
        return false;
    }

    /**
     * 获取输入框内容
     *
     * @param et
     * @return
     */
    private String getEtString(EditText et) {
        return et.getText().toString().trim();
    }

    private float getEtValue(EditText et) {
        float temp = 0f;
        try {
            String ss = et.getText().toString().trim();
            if (TextUtils.isEmpty(ss)) {
                return temp;
            }
            temp = Float.parseFloat(ss);
        } catch (Exception e) {
            showShortToast("数据异常:" + e.getMessage());
        }
        return temp;
    }

    @Override
    public void selectResult(int value, int id) {
        if (value == 1 && id == 231) {
            operatorDao.deleteByMid(cookingMenu.getId());
            saveInfo(cookingMenu.getCreateTime(), "修改成功");
        }
    }

    /**
     * 跳转选择食材页面
     *
     * @param id
     */
    private void selectFoodMaterial(int id) {
        try {
            foodNameIndex = id;
            Intent intent = new Intent(this, FoodMaterialActivity.class);
            intent.putExtra(FoodMaterialActivity.SRC_CLASS, 1);
            startActivityForResult(intent, 1025);
        } catch (Exception e) {
            showShortToast("数据异常:" + e.getMessage());
        }
    }


    @Override
    public void textInputResult(String value, int id) {
        menuTips = value;
    }

    /**
     * 显示内容输入框
     */
    private void showTextInputDialog() {
        try {
            if (textInputDialog != null) {
                textInputDialog.setTitle("食材处理要求");
                textInputDialog.setEditText1(menuTips);
                textInputDialog.showDialog(1);
            }
        } catch (Exception e) {
            showShortToast("数据异常:" + e.getMessage());
        }
    }

    @Override
    public void SingleDialogInputResult(String value, int id) {
        try {
            LocalUserDao localUserDao = new LocalUserDao(this);
            LocalUser localUser = localUserDao.queryForId(UuidUtil.getUuidByName(Constant.USER_NAME));
            if (localUser == null) {
                showLongToast("用户不存在,请联系管理员");
                return;
            }
            if (!TextUtils.equals(value, localUser.getPwd())) {
                showLongToast("输入的密码错误");
                return;
            }
            if(getEtString(etEmnuName).contains("Z")){
                showShortToast("炒菜机终端不能新建其他烹饪菜谱");
               return;
            }
            cookingMenu = cookingMenuDao.isExist(getEtString(etEmnuName), "1");
            if (cookingMenu == null || !TextUtils.equals(cookingMenu.getName(), getEtString(etEmnuName))) {
                cookingMenu = new CookingMenu();
                cookingMenu.setType(Constant.MENU_NORMAL);
                cookingMenu.setMachineModoel("M260");
                cookingMenu.setCookingType(cookingType);
                cookingMenu.setParam1(paramer1);
                cookingMenu.setParam3(paramer3);
                cookingMenu.setLevel(deviceType);
                cookingMenu.setMachineModoel(deviceType);
                cookingMenu.setParam4(paramer4);
                cookingMenu.setDesc(menuTips);
                cookingMenu.setId(UuidUtil.getUuid()+"_"+deviceType);
                saveInfo(DateTimeUtil.getCurrentTImeYMD(), "保存成功");
                CookingMenuMangerHelper.getInstance(this,new CookingMenuDao(this))
                        .updateCookingMenu(cookingMenu);
            } else if (cookingMenu != null) {
                showLongToast(cookingMenu.getName() + "已存在，请重新命名");
            }
        } catch (Exception e) {
            showShortToast("数据异常:" + e.getMessage());
        }
    }

    @Override
    public void doubleSelectResult(int value1, int id) {
        Log.e(TAG, "选择:" + value1);
        try {
            cookingType = value1;
            Intent intent = new Intent(this, CookingMenParamersSettingActivity.class);
            intent.putExtra("cookingType", value1);
            intent.putExtra("code", 1027);
            intent.putExtra("paramer1", paramer1);
            startActivityForResult(intent, 1027);
        } catch (Exception e) {
            showShortToast("数据异常:" + e.getMessage());
        }
    }





    @Override
    public void selectCatgerDialogResult(String catName, int cookingType) {
        if(catName.contains("Z")){
            showShortToast("不能选择该类型");
            return;
        }
        if(cookingType==1&&!catName.contains("X")){
            showShortToast("炒菜类型和字母标签不符，请选择带X的标签");
            return;
        }
        if(cookingType==2&&!catName.contains("Y")){
            showShortToast("炒菜类型和字母标签不符，请选择带Y的标签");
            return;
        }
        etEmnuName.setText(getEtString(etEmnuName) + catName);
    }
}